
package ejerciciostrategy;

import java.util.ArrayList;

public class NameList
{
    private ArrayList <String> names;
    private  SortStrategy sortAlgorithm;
    
    public NameList (SortStrategy strategy){
        this.sortAlgorithm= strategy;
        names= new ArrayList<String>();
   }
    
    public void addName (String name){
        
        names.add(name);
    }
    
    public void printList(){
        sortAlgorithm.sort(names);
        for (String name: names){
            System.out.println(name);
        }
    }
    
    public void printList(SortStrategy newStrategy){
        
        this.sortAlgorithm=newStrategy;
        printList();
    }
}
